<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="${contextPath}/scripts/My97DatePicker/WdatePicker.js"
	type="text/javascript"></script>
<title>协议增加</title>
<script src="${contextPath}/scripts/jquery/jquery-1.8.3.min.js"
	type="text/javascript"></script>
<script src="${contextPath}/scripts/scriptvalidator.js"
	type="text/javascript"></script>
<link href="${contextPath}/styles/default.css" rel="stylesheet"
	type="text/css" />
<script src="${contextPath}/scripts/common.js" type="text/javascript"></script>

</head>
<body>
	<div class="navigation">
		<span><a href="javascript:window.history.back();"><img
				src="${contextPath}/images/back_nav_btn.png" /></a> <a
			href="javascript:window.history.back();">返回</a> <a
			href="javascript:window.history.forward();"><img
				src="${contextPath}/images/go_nav_btn.png" /></a> <a
			href="javascript:window.history.forward();">前进</a> <a
			href="javascript:window.location.reload();"><img
				src="${contextPath}/images/refresh_nav_btn.png" /></a> <a
			href="javascript:window.location.reload();">刷新</a> </span>系统管理&gt;&gt;协议管理&gt;&gt;协议编辑
	</div>
	<div class="xt_main_right_center">
		<form name="form1" method="post" onSubmit="return checkSubmit();"
			action="save.do">
			<input type="hidden" name="redirectUrl"
				value='<s:property value='redirectUrl'/>' /> <input class="input"
				type="hidden" value="${treaty2.id }" name="treaty.id" id="treatyId" />
			<table width="100%" border="0">
				<tr>
					<td class="left-td-width-bg"><font color="red" size="2">*
					</font>4S店店号：</td>
					<td class="right-td-width-bg-left">
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td width="90%"><input class="input_readonly" name="zsasw"
									dataType="Require" msg="请选择销售店 " type="text" id="textfield"
									value="${treaty2.shop.shopMark }" readonly="readonly"></td>
								<td><a href="javascript:show();"><img
										src="${contextPath}/images/chakan.gif" alt="详细" width="16"
										height="13" border="0" /></a></td>
							</tr>
						</table>
					</td>
					<td class="left-td-width-bg"><font color="red" size="2">*
					</font>管理费收取方式：</td>
					<td><select dataType="Require" msg="请选择管理费收取方式 " class="input"
						name="treaty.collectionWay" id="select2">
							<option value="">请选择</option>
							<option
								<s:if test='treaty2.collectionWay.equals("0")'>selected="selected"</s:if>
								value="0">月付</option>
							<option
								<s:if test='treaty2.collectionWay.equals("1")'>selected="selected"</s:if>
								value="1">季付</option>
							<option
								<s:if test='treaty2.collectionWay.equals("2")'>selected="selected"</s:if>
								value="2">半年付</option>
					</select></td>
				</tr>
				<tr>
					<td class="left-td-width-bg"><font color="red" size="2">*
					</font>4S店店名：</td>
					<td class="right-td-width-bg-left"><input dataType="Require"
						class="input_readonly" msg="请选择4S店 " name="textfield2"
						value="${treaty2.shop.shopName }" type="text" id="aaa"
						readonly="readonly"></td>
					<td class="left-td-width-bg"><p>管理费标准/保底数：</p></td>
					<td class="right-td-width-bg-left"><input dataType="Double"
						msg="请输入数字 " class="input" type="text" value="<s:property value='treaty2.floors'/>"
						name="treaty.floors" id="floors"></td>
				</tr>
				<tr>
					<td class="left-td-width-bg"><font color="red" size="2">*
					</font>协议编号：</td>
					<td class="right-td-width-bg-left"><input
						dataType="Require|Unique" msg="协议编号不能为空|协议编号必须是唯一"
						classType="com.jysz.certificate.persistence.model.system.Treaty"
						valProperty="identifier" entityId="${treaty2.id}"
						contextPath="${contextPath}" class="input" type="text"
						value="${treaty2.identifier }" name="treaty.identifier"
						id="identifier"></td>
					<td class="left-td-width-bg">管理费标准/最大数：</td>
					<td class="right-td-width-bg-left"><input dataType="Double"
						msg="请输入数字 " class="input" type="text"
						value="<s:property value='treaty2.maximum'/>"
						name="treaty.maximum" id="maximum"></td>
				</tr>
				<tr>
					<td class="left-td-width-bg"><font color="red" size="2">*
					</font>协议对象：</td>
					<td class="right-td-width-bg-left"><select dataType="Require"
						msg="请选择协议对象 " class="input" name="treaty.financial.id"
						id="financialId">
							<option value="">*****请选择*****</option>
							<s:iterator value="listFinancials" status="i" id="b">
								<option
									<s:if test='treaty2.financial.id==#b.id'>selected="selected"</s:if>
									value="${b.id }">${b.name }</option>
							</s:iterator>
					</select></td>
					<td class="left-td-width-bg">单证释放价：</td>
					<td><input dataType="Double" msg="请输入数字 " class="input"
						type="text" <s:if test="#treaty2.unitPrice==0">value="<s:property value="formatAmount(0)"/>"</s:if>
						<s:else> value="<s:property value="formatAmount(treaty2.unitPrice)"/>"</s:else>
						name="treaty.unitPrice" id="unitPrice"></td>
				</tr>
				<tr>
					<td class="left-td-width-bg">合作银行：</td>
					<td class="right-td-width-bg-left"><input class="input"
						type="text" value="${treaty2.branch }" name="treaty.branch"
						id="branch"></td>
					<td class="left-td-width-bg">客户经理：</td>
					<td class="right-td-width-bg-left"><input class="input"
						type="text" value="${treaty2.manager }" name="treaty.manager"
						id="manager"></td>
				</tr>
				<tr>
					<td class="left-td-width-bg">是否有存底：</td>
					<td class="right-td-width-bg-left"><select class="input"
						name="treaty.foreignReserves" id="foreignReserves">
							<option value="">请选择</option>
							<option
								<s:if test='treaty2.foreignReserves.equals("0")'>selected="selected"</s:if>
								value="0">是</option>
							<option
								<s:if test='treaty2.foreignReserves.equals("1")'>selected="selected"</s:if>
								value="1">返还</option>
					</select></td>
					<td class="left-td-width-bg"><font color="red" size="2">*
					</font>签订时间：</td>
					<td class="right-td-width-bg-left"><input dataType="Require"
						msg="签订时间不能为空" id="dateBeg" class="Wdate" onBlur="duibi()"
						type="text" name="treaty.startDate" winth="200px"
						onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true"
						value="<s:date name="treaty2.startDate" format="yyyy-MM-dd"/>" />
					</td>
				</tr>
				<tr>
					<td class="left-td-width-bg">客户经理电话：</td>
					<td class="right-td-width-bg-left"><input dataType="Mobile"
						msg="联系方式数据错误 " class="input" type="text"
						value="${treaty2.conductorPhone }" name="treaty.conductorPhone"
						id="branch"></td>
					<td class="left-td-width-bg"><font color="red" size="2">*
					</font>结束时间：</td>
					<td class="right-td-width-bg-left"><input dataType="Require"
						msg="结束时间不能为空" id="dateEnd" class="Wdate" onBlur="duibi()"
						type="text" name="treaty.endDate" winth="200px"
						onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true"
						value="<s:date name="treaty2.endDate" format="yyyy-MM-dd"/>" />
						<div id="iDBody1" style="display: none">
							<font color="red" size="2">结束时间要晚于签订时间，请检查</font>
						</div></td>
				</tr>
				<tr>
					<td class="left-td-width-bg">状态：</td>
					<td class="right-td-width-bg-left"><select class="input"
						name="treaty.state" id="treatyState">
							<option
								<s:if test='treaty2.state==true'>selected="selected"</s:if>
								value="true">启用</option>
							<option
								<s:if test='treaty2.state==false'>selected="selected"</s:if>
								value="false">禁止</option>
					</select></td>
					<td class="left-td-width-bg">客户经理邮箱：</td>
					<td class="right-td-width-bg-left"><input dataType="Email"
						msg="邮箱格式错误 " class="input" type="text"
						value="${treaty2.conductorEmile }" name="treaty.conductorEmile"
						id="branch2"></td>
				</tr>
				<tr>
					<td class="left-td-width-bg">备注</td>
					<td class="right-td-width-bg-left"><input class="input"
						type="text" value="${treaty2.remark }" name="treaty.remark"
						id="remark"></td>
					<td class="left-td-width-bg">&nbsp;</td>
					<td class="right-td-width-bg-left">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="4" align="center"><input class="input"
						type="hidden" value="${treaty2.shop.id }" name="shopID"
						id="SHOPID"> <input type="submit" class="btn_save"
						name="button" id="button" value=""> <input type="button"
						name="button2" class="btn_rest"
						onClick="clearForm(this.form);return false;"></td>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<br />
	<br />
	<br />
	<br />
	<br />
	<div><jsp:include page="/include/footer.inc"></jsp:include></div>
	<script language='javascript'>
		function duibi(shopId, fianId, dateEnd) {
			var a = document.getElementById("dateBeg").value;
			var b = document.getElementById("dateEnd").value;
			var foreignReserves = document.getElementById("treatyState").value;
			var treatyId = document.getElementById("treatyId").value;
			if (null != a && null != b) {
				var arr = a.split("-");
				var starttime = new Date(arr[0], arr[1], arr[2]);
				var starttimes = starttime.getTime();

				var arrs = b.split("-");
				var lktime = new Date(arrs[0], arrs[1], arrs[2]);
				var lktimes = lktime.getTime();

				if (starttimes >= lktimes) {
					document.getElementById('iDBody1').style.display = "";
					return false;
				} else {
					document.getElementById('iDBody1').style.display = "none";
					doAjaxTest(shopId, fianId, dateEnd, foreignReserves,
							treatyId);
					if (bo == false) {
						if (confirm("已存在相同的协议，是否禁用冲突协议！")) {
							$
									.ajax({
										async : false,
										type : 'POST',
										url : "<s:property value='contextPath'/>/system/treaty/forbiddenTreaty.do?benginDate="
												+ dateEnd
												+ "&shopID="
												+ shopId
												+ "&financialId="
												+ fianId
												+ "&foreignReserves="
												+ foreignReserves
												+ "&id="
												+ treatyId,
										dataType : "json",
										success : function(data) {
										}
									});
							return true;
						} else {
							return bo;
						}
					}

				}
			} else {
				return true;
			}
		}
		function checkSubmit() {
			var money = document.getElementById("floors").value;
			while(money.indexOf(",")>-1){
				money = money.replace(",","");
			}
			document.getElementById("floors").value = money;
			var shopId = document.getElementById("SHOPID").value;
			var fianId = document.getElementById("financialId").value;
			var dateEnd = document.getElementById("dateBeg").value;
			var staffForm = document.form1;
			if (!Validator.Validate(staffForm, 3)) {
				return false;
			}
			return this.duibi(shopId, fianId, dateEnd);
		}
		function show() {
			window
					.open(
							"selectShop.do",
							"newwindow",
							"height=450, width=700, toolbar =no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
		}
		function selectShopCallBack(hao, ming, id) {
			document.getElementById("textfield").value = hao;
			document.getElementById("SHOPID").value = id;
			document.getElementById("aaa").value = ming;
		}
		var bo = true;
		function doAjaxTest(shopId, fianId, dateEnd, foreignReserves, id) {
			bo = true;
			$
					.ajax({
						async : false,
						type : 'POST',
						url : "<s:property value='contextPath'/>/system/treaty/efficacyTreaty.do?benginDate="
								+ dateEnd
								+ "&shopID="
								+ shopId
								+ "&financialId="
								+ fianId
								+ "&foreignReserves="
								+ foreignReserves
								+ "&id=" + id,
						dataType : "json",
						success : function(data) {
							if (data) {
								bo = false;
							}
						}
					});

		}
	</script>
</body>
</html>